home *** CD-ROM | disk | FTP | other *** search
- Path: news.interpath.net!usenet
- From: "Richard F. Albury" <richard.albury@virtus.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Coding Standards
- Date: Tue, 19 Mar 1996 08:56:24 -0500
- Organization: Virtus Corporation
- Message-ID: <314EBD08.43BC@virtus.com>
- References: <4hj8ek$elu@sam.inforamp.net> <4hktar$5o2@galaxy.ucr.edu> <4hmqol$97j@abacus.abasoft.co.uk> <4hsg8r$pmm@sam.inforamp.net> <4i9o6j$p4l@daisy.pgh.wec.com> <4idskb$pc1@sam.inforamp.net>
- NNTP-Posting-Host: albury-win.virtus.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- > -inline C++ functions should be in a file with the extension .icc (not
- > in the primary header).
- > I don't think I have to say anything here either. But, I
- > will. Although I've seen many people do this, it is contrary to normal
- > industry practices. By using non-standard practices you increase the learning
- > necessary for new employees. Bad.
-
- Hmm. All the PC and Mac compilers I've seen do this. Given a class TFoo, the
- class is defined in Foo.h and the inlines are in Foo.inl. The user includes
- only Foo.h, allowing the implementor to move things between the files Foo.h and
- Foo.inl at will with minimal impact to the user.
-
- > -do not use the /* */ comment, except when commenting out entire
- > sections of code.
- > /* */ are the ANSI standard comment. // are not. When you have a
- > parameter not used warning, you should eliminate it using.
- > void f(int /* idControl */);
- > You can't do this with //. You could also delete the identifier, but then you
- > would lose context.
-
- // is the standard C++ comment, so I'm not sure I understand your objection.
-
- > -a class which can be instantiated with a "new" must have a copy
- > constructor, a destructor and an assignment operator definition.
- > Most compilers (if not all) supply default copy construtors. Unless
- > you think your class may have copy behavior problems, then writing copy
- > constructors is redundant. When you have 100+ classes to write and where the
- > average copy constructor has 50 lines, you would need 100 hours to write the
- > additional robustness (or cumbersomeness).
-
- It's good discipline. Read Scott Meyers' books for more info.
-
- > -never use #define instead or const.
- > This is a good debate, but I still maintain that if your memory model
- > and compiler make #define data text and const code text, then you cannot
- > consider this a straight forward trade-off.
-
- Granted, there are implementation issues which in a small set of cases might
- make the use of const a problem, but const is typesafe, while #define is not.
- The whole purpose for using C++ is to attempt to adhere to the OO principles
- of encapsulation, abstraction, and polymorphism.
-
- > -every case statement must be terminated with a break statement.
- > Why? This is arbitrary and makes some programming algorithms harder
- > to implement. Example: the messages handling switch statement. You usually
- > break to fall to the default handling and return to skip the default handling.
-
- The switch statement is one of C's worst "features." Inadvertently leaving off
- a break can be hard to track down.
-
- > -optimize code only when you have a problem.
- > Why not anticipate the problem?
-
- You rarely can. Read Plauger's writings on style. One of his sayings is
- "First make it right, then make it fast." If performance is an issue, use a
- profiler.
-
- > -access functions are to be inline.
- > This is the biggest fallacy in programming today. If you make your
- > accessors inline, then you have defeated the purpose of data hiding. If your
- > data's type changes, then you still have to recompile every object that
- > accesses the member.
-
- Agreed.
-
- > -give protected accessors for all data members.
- > Proper encapsulation tells us otherwise.
-
- Ditto.
-